from django.db import models


# Create your models here.
# 用户
class User(models.Model):
    name = models.CharField(default="", max_length=20, verbose_name="昵称")
    phone = models.CharField(default="", max_length=20, verbose_name="账号")
    password = models.CharField(default="", max_length=50, verbose_name="密码")
    remark = models.CharField(default="", max_length=255, verbose_name="备注")
    status = models.IntegerField(default=1, verbose_name="用户状态")
    is_delete = models.IntegerField(default=0, verbose_name="是否删除")
    creator = models.CharField(default="Admin", verbose_name="创建者", max_length=20)
    role = models.ForeignKey("Role", related_name="role", verbose_name="角色", on_delete=models.CASCADE)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

    def __str__(self):
        return self.name


# 角色
class Role(models.Model):
    name = models.CharField(default="", max_length=100, verbose_name="名称")
    remark = models.CharField(default="", max_length=255, verbose_name="备注")
    status = models.IntegerField(default=1, verbose_name="是否禁用")
    is_delete = models.IntegerField(default=0, verbose_name="是否删除")
    permission = models.ManyToManyField("Permission", related_name="permission", verbose_name="权限")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")


# 权限
class Permission(models.Model):
    name = models.CharField(default="", max_length=100, verbose_name="名称")
    route = models.CharField(default="", max_length=100, verbose_name="路由")
    remark = models.CharField(default="", max_length=255, verbose_name="备注")
    status = models.IntegerField(default=1, verbose_name="状态")
    is_delete = models.IntegerField(default=0, verbose_name="是否删除")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")


# 操作记录
class UserDoLog(models.Model):
    action_type = models.IntegerField(default=0, verbose_name="操作类型")    # 操作类型 0-未知
    what = models.CharField(default="", max_length=255, verbose_name="做了什么")
    who = models.CharField(default="", max_length=50, verbose_name="用户")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
